﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 日期选择器
{
    public partial class Form1 : Form
    {
        public static bool judge = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void cboyear_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (judge == false)
            {
                for (int i = 1; i <= 12; i++)
                {
                    cbomonth.Items.Add(i + "月");
                }
                judge = true;
            }
            else
            {
                cbomonth_SelectedIndexChanged(sender, e);
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            int year = DateTime.Now.Year;
            for (int i = year; i >= 1949; i--)
            {
                cboyear.Items.Add(i + "年");
            }
        }

        private void cbomonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            cboday.Items.Clear();
            int year,month;
            int[] day = new int[13] { 0, 31, 28,31,30,31,30,31,31,30,31,30,31};
            string temp = cboyear.Items[cboyear.SelectedIndex].ToString();
            string[] x=temp.Split('年');
            int.TryParse(x[0], out year);
            temp = cbomonth.Items[cbomonth.SelectedIndex].ToString();
            x = temp.Split('月');
            int.TryParse(x[0], out month);
            if(month==2)
            {
                if(year%400==0||(year%4==0&&year%100!=0))
                {
                    day[2] = 29;
                }
            }
            for(int i=1;i<=day[month];i++)
            {
                cboday.Items.Add(i + "日");
            }
        }
    }
}